
package stratego.java.ssm;

import stratego.java.ssm.piece.BlockPiece;
import stratego.java.ssm.piece.EmptyPiece;
import stratego.java.ssm.piece.Piece;

/**
 * <code>public class Board</code>
 * <p>
 * This class serves as the board for some user. This object needs to be aware of the current
 * location of both player's piece.
 * </p>
 * 
 * @author Mark Aligbe
 * 
 */
public class Board
{
	private Piece[][]	board;
	// The type of the board
	public static final String	CLASSIC	= "classic", CUSTOM = "custom";
	
	/**
	 * <code>public Board(String type)</code>
	 * <p>
	 * Constructs a new board using the default
	 * 
	 * @param type
	 */
	public Board(String type, int size)
	{
		if (type.equals(CLASSIC))
			buildDefaultBoard();
		else if (type.equals(CUSTOM))
			buildCustomBoard(size);
	}
	
	/**
	 * <code>public void buildCustomBoard(int size)</code>
	 * <p>
	 * Constructs a new board object with the given size. Ranges from board[0][0] to
	 * board[size-1][size-1].
	 * </p>
	 * 
	 * @param size
	 *            - The size of the board.
	 */
	private void buildCustomBoard(int size)
	{
		board = new Piece[size][size];
		// Iterate through the board in normal Cartesian coordinates
		for (int y = board.length - 1; y >= 0; y--)
			for (int x = 0; x < board.length; x++)
				board[x][y] = new EmptyPiece();
	}
	
	/**
	 * <code>private void buildDefaultBoard()</code>
	 * <p>
	 * Initializes the board object of this class with the default board. 2, 2x2 squares in the
	 * middle of the map are made BlockPieces. Everything else becomes and EmptyPiece.
	 * </p>
	 */
	private void buildDefaultBoard()
	{
		// The classic board is 10x10
		board = new Piece[10][10];
		// Create two squares of BlockPieces in the center of the map at (2,4)-(3,5) and at
		// (6,4)-(6,5)
		for (int y = 5; y >= 4; y--)
		{
			for (int x = 0; x < 2; x++)
			{
				board[2 + x][y] = new BlockPiece();
				board[6 + x][y] = new BlockPiece();
			}
		}
		// Fills in all other squares with EmpptyPieces
		for (int y = board.length - 1; y >= 0; y--)
		{
			for (int x = 0; x < board.length; x++)
			{
				if (board[x][y] == null)
					board[x][y] = new EmptyPiece();
			}
		}
	}
	
	/**
	 * <code>public Piece[][] getBoard()</code>
	 * <p>
	 * Returns a modifiable view of the board object represented by this class
	 * </p>
	 * 
	 * @return A Piece[][] containing the current pieces in play
	 */
	public Piece[][] getBoard()
	{
		return board;
	}
}
